<html>
<head><meta charset="utf-8"><title>Coerce trait object to another · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html">Coerce trait object to another</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182343314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343314">(Dec 02 2019 at 13:15)</a>:</h4>
<p>Is there a simple way to coerce one trait object to another? e.g.</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Debug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="n">_</span><span class="p">];</span><span class="w"></span>
</pre></div>


<p>?</p>



<a name="182343456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343456">(Dec 02 2019 at 13:16)</a>:</h4>
<p>you only have one trait object here?</p>



<a name="182343522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343522">(Dec 02 2019 at 13:17)</a>:</h4>
<p>yes</p>



<a name="182343571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343571">(Dec 02 2019 at 13:18)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="n">_</span><span class="p">];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Debug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"></span>
</pre></div>


<p>works</p>



<a name="182343572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343572">(Dec 02 2019 at 13:18)</a>:</h4>
<p>so I don't really understand what you're asking</p>



<a name="182343583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343583">(Dec 02 2019 at 13:18)</a>:</h4>
<p>the <code>as &amp;[_]</code> isn't doing anything there</p>



<a name="182343592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343592">(Dec 02 2019 at 13:18)</a>:</h4>
<p>(indeed I'm somewhat surprised that compiles)</p>



<a name="182343596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343596">(Dec 02 2019 at 13:18)</a>:</h4>
<p><code>let v: &amp;dyn std::fmt::Debug = &amp;[0, 2, 3];</code> just works</p>



<a name="182343735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343735">(Dec 02 2019 at 13:20)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=15d52f7f88a06a34c752da1a55fbbae8" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=15d52f7f88a06a34c752da1a55fbbae8">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=15d52f7f88a06a34c752da1a55fbbae8</a></p>



<a name="182343766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343766">(Dec 02 2019 at 13:20)</a>:</h4>
<p>The <code>&amp;[_]</code> coerces a <code>&amp;[T; N]</code> into a <code>&amp;[T]</code></p>



<a name="182343857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343857">(Dec 02 2019 at 13:21)</a>:</h4>
<p>hm, right</p>



<a name="182343864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343864">(Dec 02 2019 at 13:21)</a>:</h4>
<p>yeah, you can't do this</p>



<a name="182343871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343871">(Dec 02 2019 at 13:21)</a>:</h4>
<p>since we can't inherit from a vtable</p>



<a name="182343899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343899">(Dec 02 2019 at 13:22)</a>:</h4>
<p>what do you mean with "inherit" ?</p>



<a name="182343952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343952">(Dec 02 2019 at 13:22)</a>:</h4>
<p>Slices do implement <code>Debug</code> right ?</p>



<a name="182343961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182343961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182343961">(Dec 02 2019 at 13:22)</a>:</h4>
<p>well, okay, I should say that differently</p>



<a name="182344006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344006">(Dec 02 2019 at 13:22)</a>:</h4>
<p>basically <code>&amp;[T]</code> is not sized, so <code>&amp;dyn fmt::Debug</code> has nowhere to 'put' the pointer to <code>self</code></p>



<a name="182344023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344023">(Dec 02 2019 at 13:23)</a>:</h4>
<p>(since trait objects are always 2 ptrs today)</p>



<a name="182344067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344067">(Dec 02 2019 at 13:23)</a>:</h4>
<p>where is the vtable of <code>&lt;&amp;[T] as Debug&gt;</code> ?</p>



<a name="182344153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344153">(Dec 02 2019 at 13:24)</a>:</h4>
<p>ahh i think i see the problem</p>



<a name="182344160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344160">(Dec 02 2019 at 13:24)</a>:</h4>
<p>where? The vtable exists and you can do that</p>



<a name="182344171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344171">(Dec 02 2019 at 13:24)</a>:</h4>
<p>but you can't "fit" it into <code>&amp;dyn fmt::Debug</code></p>



<a name="182344179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344179">(Dec 02 2019 at 13:24)</a>:</h4>
<p>So we can point the vtable pointer of <code>dyn fm::Debug</code> to the vtable</p>



<a name="182344206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344206">(Dec 02 2019 at 13:25)</a>:</h4>
<p>yes, that works (and is indeed always the case)</p>



<a name="182344209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344209">(Dec 02 2019 at 13:25)</a>:</h4>
<p>the problem is the self pointer</p>



<a name="182344218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344218">(Dec 02 2019 at 13:25)</a>:</h4>
<p>damn,</p>



<a name="182344222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344222">(Dec 02 2019 at 13:25)</a>:</h4>
<p>but then you only have one pointer left for the self pointer, and you need two</p>



<a name="182344237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344237">(Dec 02 2019 at 13:25)</a>:</h4>
<p>but if you need to do this and the lifetimes work out, <code>let _x: &amp;dyn std::fmt::Debug = &a;</code> would work</p>



<a name="182344250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344250">(Dec 02 2019 at 13:25)</a>:</h4>
<p>one needs two because &amp;[T] is a fat pointer, not a thin one</p>



<a name="182344309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344309">(Dec 02 2019 at 13:26)</a>:</h4>
<p>e.g. if <code>&amp;[T]</code> was a thin pointer to <code>[len, padding, [elements: T, T, T, ...]]</code></p>



<a name="182344321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344321">(Dec 02 2019 at 13:26)</a>:</h4>
<p>it would work</p>



<a name="182344329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344329">(Dec 02 2019 at 13:26)</a>:</h4>
<p>but then you can't have subslices</p>



<a name="182344387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344387">(Dec 02 2019 at 13:26)</a>:</h4>
<p>correct</p>



<a name="182344399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344399">(Dec 02 2019 at 13:27)</a>:</h4>
<p>damn</p>



<a name="182344417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344417">(Dec 02 2019 at 13:27)</a>:</h4>
<p>there is no good solution to this</p>



<a name="182344424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344424">(Dec 02 2019 at 13:27)</a>:</h4>
<p>well, I mean, it depends on your use case</p>



<a name="182344432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344432">(Dec 02 2019 at 13:27)</a>:</h4>
<p>you can manually make the bigger vtable</p>



<a name="182344440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344440">(Dec 02 2019 at 13:27)</a>:</h4>
<p>So I have a big array, that doesn't have a Debug impl</p>



<a name="182344447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344447">(Dec 02 2019 at 13:27)</a>:</h4>
<p>I need to pass it to an API that takes <code>&amp;dyn Debug</code></p>



<a name="182344459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344459">(Dec 02 2019 at 13:28)</a>:</h4>
<p>and I thought I could be smarter by just coercing it to a slice</p>



<a name="182344499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344499">(Dec 02 2019 at 13:28)</a>:</h4>
<p>oh that you can definitely do</p>



<a name="182344511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344511">(Dec 02 2019 at 13:28)</a>:</h4>
<p>just do &amp;&amp;[...]`</p>



<a name="182344525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344525">(Dec 02 2019 at 13:28)</a>:</h4>
<p>because <code>&amp;&amp;[u32]</code> is not fat</p>



<a name="182344604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344604">(Dec 02 2019 at 13:29)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> does that work for you?</p>



<a name="182344611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344611">(Dec 02 2019 at 13:29)</a>:</h4>
<p>yeah</p>



<a name="182344697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344697">(Dec 02 2019 at 13:30)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">128</span><span class="p">];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Debug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">[..];</span><span class="w"></span>
</pre></div>



<a name="182344699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344699">(Dec 02 2019 at 13:30)</a>:</h4>
<p>that works</p>



<a name="182344719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344719">(Dec 02 2019 at 13:30)</a>:</h4>
<p>note that the type there is <code>&amp;'a (dyn Debug + 'b)</code> I believe, not <code>+ 'static</code> like normally</p>



<a name="182344771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344771">(Dec 02 2019 at 13:31)</a>:</h4>
<p>but for the most part you probably don't care</p>



<a name="182344788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344788">(Dec 02 2019 at 13:31)</a>:</h4>
<p>Is there an impl of Debug for &amp;T where T: Debug ?</p>



<a name="182344797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344797">(Dec 02 2019 at 13:31)</a>:</h4>
<p>or how does that work internally ?</p>



<a name="182344800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344800">(Dec 02 2019 at 13:31)</a>:</h4>
<p>hm, perhaps?</p>



<a name="182344817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344817">(Dec 02 2019 at 13:31)</a>:</h4>
<p>rustdoc says yes</p>



<a name="182344822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344822">(Dec 02 2019 at 13:31)</a>:</h4>
<p>and for &amp;mut T</p>



<a name="182344829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344829">(Dec 02 2019 at 13:31)</a>:</h4>
<p>so that makes sense</p>



<a name="182344855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344855">(Dec 02 2019 at 13:32)</a>:</h4>
<p>thanks</p>



<a name="182344905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344905">(Dec 02 2019 at 13:32)</a>:</h4>
<p>so i wonder if this works, why can't the initial coercion work ?</p>



<a name="182344929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344929">(Dec 02 2019 at 13:32)</a>:</h4>
<p>like the pointer to self would be a pointer to the slice object</p>



<a name="182344991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182344991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182344991">(Dec 02 2019 at 13:33)</a>:</h4>
<p>because we don't double coerce or so</p>



<a name="182345011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345011">(Dec 02 2019 at 13:33)</a>:</h4>
<p>i.e., you've not given that pointer, so we won't make it ourselves</p>



<a name="182345023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345023">(Dec 02 2019 at 13:33)</a>:</h4>
<p>but we do that when creating a slice</p>



<a name="182345111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345111">(Dec 02 2019 at 13:34)</a>:</h4>
<p>hm, how so?</p>



<a name="182345133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345133">(Dec 02 2019 at 13:34)</a>:</h4>
<p>e.g. when doing <code>&amp;[T; N] as &amp;[T]</code> we create the slice trait object, with a pointer, and a length - notice that the length did not exist in memory anywhere, since is part of the type</p>



<a name="182345153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345153">(Dec 02 2019 at 13:34)</a>:</h4>
<p>the length is the vtable bit though</p>



<a name="182345170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345170">(Dec 02 2019 at 13:34)</a>:</h4>
<p>which is always synthesized out of "nowhere"</p>



<a name="182345181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345181">(Dec 02 2019 at 13:34)</a>:</h4>
<p>the pointer is "constant"</p>



<a name="182345257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345257">(Dec 02 2019 at 13:35)</a>:</h4>
<p>ah, wait, by double-coerce you mean that we don't create pointers out of nowhere ?</p>



<a name="182345325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345325">(Dec 02 2019 at 13:36)</a>:</h4>
<p>e.g. for <code>&amp;[T; N] as &amp;[T] as &amp;dyn Debug</code> we'd need to create a pointer to the <code>&amp;[T]</code> and coerce that pointer to <code>&amp;dyn Debug</code></p>



<a name="182345356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345356">(Dec 02 2019 at 13:36)</a>:</h4>
<p>yes</p>



<a name="182345359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345359">(Dec 02 2019 at 13:36)</a>:</h4>
<p>so this works: <code>&amp;(&amp;[T; N] as &amp;[T]) as &amp;dyn Debug</code> because we don't have to create any pointers for that</p>



<a name="182345373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345373">(Dec 02 2019 at 13:36)</a>:</h4>
<p>(the user created it)</p>



<a name="182345378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345378">(Dec 02 2019 at 13:36)</a>:</h4>
<p>that's my understanding, yeah</p>



<a name="182345389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182345389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182345389">(Dec 02 2019 at 13:37)</a>:</h4>
<p>thanks, i think i've got this</p>



<a name="182377424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182377424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> csmoe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182377424">(Dec 02 2019 at 18:59)</a>:</h4>
<blockquote>
<p>basically <code>&amp;[T]</code> is not sized, so <code>&amp;dyn fmt::Debug</code> has nowhere to 'put' the pointer to <code>self</code></p>
</blockquote>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> did you mean <code>[T]</code> is not sized? I used to think <code>&amp;[T]</code>is sized, am I wrong? <span aria-label="fear" class="emoji emoji-1f628" role="img" title="fear">:fear:</span></p>



<a name="182377448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182377448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182377448">(Dec 02 2019 at 18:59)</a>:</h4>
<p>er, s/sized/thin</p>



<a name="182460664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182460664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182460664">(Dec 03 2019 at 15:37)</a>:</h4>
<blockquote>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="o">&amp;</span><span class="p">[</span><span class="n">_</span><span class="p">];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">b</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">Debug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">a</span><span class="p">;</span><span class="w"></span>
</pre></div>


<p>works</p>
</blockquote>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span>  I was very surprised that it should work and when <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=192b9de62b5db577a762b5d3cc4994a5" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=192b9de62b5db577a762b5d3cc4994a5">I tried it didn't</a>... is there a typo here?</p>



<a name="182460866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182460866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182460866">(Dec 03 2019 at 15:38)</a>:</h4>
<p>I think so</p>



<a name="182460913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182460913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182460913">(Dec 03 2019 at 15:39)</a>:</h4>
<p>I might have had a typo in my playground, this works: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e830ca21ef05fcccba30958d2da231bb" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e830ca21ef05fcccba30958d2da231bb">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=e830ca21ef05fcccba30958d2da231bb</a></p>



<a name="182460968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182460968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182460968">(Dec 03 2019 at 15:39)</a>:</h4>
<p>but that works due to the <code>Debug</code> impl for small arrays</p>



<a name="182461052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Coerce%20trait%20object%20to%20another/near/182461052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Coerce.20trait.20object.20to.20another.html#182461052">(Dec 03 2019 at 15:40)</a>:</h4>
<p>this doesn't work: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fa83c860d4092b312eb0e2af615cc1b1" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fa83c860d4092b312eb0e2af615cc1b1">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=fa83c860d4092b312eb0e2af615cc1b1</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>